package cn.ekuma.epos.datalogic.define.dao.erp.subject;

import com.openbravo.bean.erp.subject.Subject;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

import cn.ekuma.data.dao.ModifiedLogDAO;
import cn.ekuma.epos.db.table.erp.subject.I_Subject;

public class SubjectDAO extends ModifiedLogDAO<Subject>{

	public SubjectDAO(I_Session s) {
		super(s);
	}

	@Override
	public Subject readValues(DataRead dr,Subject obj) throws BasicException {
		if(obj==null)
			obj=new Subject();
		obj.setId(dr.getString(1));
		obj.setName(dr.getString(2));
		obj.setState(dr.getString(3));
		obj.setStartDate(dr.getTimestamp(4));
		obj.setEndDate(dr.getTimestamp(5));
		obj.setEvaluation(dr.getString(6));
		obj.setMemo(dr.getString(7));
		obj.setLastModified(dr.getTimestamp(8));
		return obj;
	}

	@Override
	public TableDefinition getTable() {
		return new TableDefinition(s,
                "SUBJECT",
                new Field[]{
                   new Field(I_Subject.ID,Datas.STRING, Formats.STRING),
                   new Field(I_Subject.NAME,Datas.STRING, Formats.STRING),
                   new Field(I_Subject.STATE,Datas.STRING, Formats.STRING),
                   new Field(I_Subject.STARTDATE,Datas.TIMESTAMP, Formats.TIMESTAMP),
                   new Field(I_Subject.ENDDATE,Datas.TIMESTAMP, Formats.TIMESTAMP),
                   new Field(I_Subject.EVALUATION,Datas.STRING, Formats.STRING),
                   new Field(I_Subject.MEMO,Datas.STRING, Formats.STRING),
                   new Field(I_Subject.LASTMODIFIED,Datas.TIMESTAMP, Formats.TIMESTAMP)
                 },
                new int[]{0}
                );
	}

	@Override
	public void writeInsertValues(DataWrite dp, Subject obj)
			throws BasicException {
		dp.setString(1,obj.getId());
		dp.setString(2,obj.getName());
		dp.setString(3,obj.getState());
		dp.setTimestamp(4,obj.getStartDate());
		dp.setTimestamp(5,obj.getEndDate());
		dp.setString(6,obj.getEvaluation());
		dp.setString(7,obj.getMemo());
		dp.setTimestamp(8,obj.getLastModified());
	}

	@Override
	public Class getSuportClass() {
		return Subject.class;
	}

}
